﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace ConsoleApp1
{
    class gg
    {
        private readonly string sqlCommandString = "select * from Student";

        private readonly string connectionString = "server=.;database=Study;uid=sa;pwd=LINYUHUI659";
        public static void Student()
        {

            string connectionString = "server=.;database=Study;uid=sa;pwd=123456789";

            SqlConnection sqlConnection = new SqlConnection(connectionString);

            sqlConnection.Open();

            string sqlCommandString = "select * from Student";

            SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);

            var sdr = sqlCommand.ExecuteReader();

            Console.WriteLine("{0}\t{1}\t{2}", "Id", "Name", "Source");

            while (sdr.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}", sdr["Id"], sdr["StudentName"], sdr["score"]);
            }
            sqlConnection.Close();

        }

             public void Student1()
            {

            SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommandString, connectionString);

            DataTable dataTable = new System.Data.DataTable();

            dataAdapter.Fill(dataTable);
            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("{0}\t{1}\t{2}", "Id", "Name", "source");

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}", dataTable.Rows[i]["Id"], dataTable.Rows[i]["StudentName"], dataTable.Rows[i]["Score"]);
            }





        }
    }
}

